#include "cat.h"
#include "master.h"
/*
学习内容:
1、友元函数,友元类
2、操作符重载
*/
//类的友元函数可以直接访问该类对象的私有成员
void friend_fun()
{
	Cat * p_cat = new Cat(2, "小花");
	cout << p_cat->age << endl;
	cout << p_cat->name << endl;

	Master * p_master = new Master(p_cat);
	p_master->show_cat();
	delete(p_cat);
	delete(p_master);
}


//操作符重载
void operator_overload()
{
	Cat * p_cat1 = new Cat(2, "小花");
	Cat * p_cat2 = new Cat(3, "小白");

	//重载了 += 符
	//  *p_cat1 += *p_cat2;
	//  cout << p_cat1->age <<endl;//5

	//重载了 > 操作符
	// bool b =  (*p_cat1 > *p_cat2);
	// cout << b << endl;

	//重载了+号操作符
	//  *p_cat1 = *p_cat1 + *p_cat2;
	//   cout << p_cat1->age <<endl;
	//   cout << p_cat1->name <<endl;//5 小花小白
	Cat cat3 = (*p_cat1)++;
	Cat cat4 = ++(*p_cat2);
	cout << cat3.age << endl;
	cout << cat3.name << endl;
	cout << cat4.age << endl;
	cout << cat4.name << endl;
	delete(p_cat1);
	delete(p_cat2);
}
//二元操作符重载
string operator+(string str1, string str2)
{
	string str = str1.append("-").append(str2);
	return str;
}
//使用操作符重载连接字符串
void test_string_add() {
	string s1 = "hello";
	string s2 = "world";
	string s3 = s1 + s2;
	cout << s3 << endl;
}

int _3main()
{

	//friend_fun();
	operator_overload();
	system("pause");
	return 0;
}